/**
 * This is really annoying that in Java there is not "eval" function as in python
 * So I need to write parsers to have arrays from their list representation
 */
package common;

/**
 * @author vladimir
 * 
 */
public class String2Array {
	// function that returns 2d int array from corresponding string
	public static int[][] Str2int2(String input) {
		// first of all lets remove "{{" and "}}" and remove all " "
		String modInput = input.replace("{{", "").replace("}}", "")
				.replace(" ", "");

		String[] mod2Input = modInput.split("\\},\\{");

		int dim1 = mod2Input.length;
		int dim2 = (mod2Input[0]).split(",").length;

		int[][] result = new int[dim1][dim2];

		for (int x = 0; x < dim1; x++) {
			String[] element = (mod2Input[x]).split(",");
			for (int y = 0; y < dim2; y++) {
				result[x][y] = Integer.parseInt(element[y]);
			}
		}
		return result;
	}
}
